<div id="photos">
    {% for photo in photos %}
        {% if forloop.first %}<div class="row">{% endif %}
        {% if forloop.counter0|divisibleby:3 and not forloop.first %}
            </div><div class="row">
        {% endif %}

        <div class="span3">
            <div class="thumbnail">
                <img src="{{ photo.image.url }}" alt="{{ photo.name }}" />
                <div class="caption">{{ photo.name }}</div>
            </div>
        </div>

        {% if forloop.last %}</div>{% endif %}
    {% empty %}
        <h4 class="well">There are no photos yet.</h4>
    {% endfor %}
</div>